package Chapter6;

import java.util.Vector;

//120页例6.3 单重继承
//说明只要是public 其子类可以访问父类的公共方法或成员；即便成员是私有/保护的，但仍可以通过公有的方法间接访问私有成员

/*class Person {
    public String name;

    public String getName() {//若private/protected String name; 即便成员name是私有/保护的，但仍可以通过公有的方法间接访问私有成员
        return name;
    }

    public void setName(String n) {
        name = n;
    }
}

class Employee extends Person {
    public int employeeNumber; //雇员编号

    public int getEmployeeNumber() {
        return employeeNumber;
    }
}

class Manager extends Employee {
    public String department; //部门
    public Vector<String> responsibilities; //计划

    public Vector<String> getResponsibilities() {
        return responsibilities;
    }
}

public class PersonTest{
    public static void main(String[] args) {
        Employee jim = new Employee();
        jim.name = "jim"; //Person的成员变量
        jim.employeeNumber = 1001; //employee的成员变量
        System.out.println("雇员的名称："+jim.getName());
        System.out.println("雇员的编号："+jim.getEmployeeNumber());

        Manager betty = new Manager();
        betty.name="Betty"; //Person的成员变量
        betty.employeeNumber = 2001; //employee的成员变量
        betty.responsibilities = new Vector<String>(); //自己的成员变量
        betty.responsibilities.add("互联网项目");
        betty.responsibilities.add("手机程序项目");
        System.out.println("经理的名称："+betty.getName());
        System.out.println("经理的编号："+betty.getEmployeeNumber());
        System.out.println("经理的项目："+betty.getResponsibilities());
    }
}
*/


//122页例6.6 单重继承+对象转型
class Person {
    public String name;

    public String getName() {//若private/protected String name; 即便成员name是私有/保护的，但仍可以通过公有的方法间接访问私有成员
        return name;
    }

    public void setName(String n) {
        name = n;
    }
}

class Employee extends Person {
    public int employeeNumber; //雇员编号

    public int getEmployeeNumber() {
        return employeeNumber;
    }
}

class Manager extends Employee {
    public String department; //部门
    public Vector<String> responsibilities; //计划

    public Vector<String> getResponsibilities() {
        return responsibilities;
    }
}

public class PersonTest{
    public static void main(String[] args) {
        Employee jim = new Employee();
        jim.name = "jim"; //Person的成员变量
        jim.employeeNumber = 1001; //employee的成员变量
        System.out.println("雇员的名称："+jim.getName());
        System.out.println("雇员的编号："+jim.getEmployeeNumber());

        Manager betty = new Manager();
        betty.name="Betty"; //Person的成员变量
        betty.employeeNumber = 2001; //employee的成员变量
        betty.responsibilities = new Vector<String>(); //自己的成员变量
        betty.responsibilities.add("互联网项目");
        betty.responsibilities.add("手机程序项目");
        System.out.println("经理的名称："+betty.getName());
        System.out.println("经理的编号："+betty.getEmployeeNumber());
        System.out.println("经理的项目："+betty.getResponsibilities());
    }
}
